﻿using B.S.DataBase.MyProject.ErrorCode;
using B.S.Traceability.Domain;
using B.S.Traceability.Infrastructure.Interface;
using B.S.Traceability.Read.API.Applicantion.Command.GoodsCommand;
using MediatR;

namespace B.S.Traceability.Read.API.Applicantion.CommandHandler.GoodsCommandHandler
{
    public class QueryGoodNameCommandHandler : IRequestHandler<QueryGoodNameCommand, APIResult<List<SU_GoodName>>>
    {
        private readonly IBaseRepository<SU_GoodName> goodNameRep;
        public QueryGoodNameCommandHandler(IBaseRepository<SU_GoodName> goodNameRep)
        {
            this.goodNameRep = goodNameRep;
        }

        public Task<APIResult<List<SU_GoodName>>> Handle(QueryGoodNameCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<SU_GoodName>> result=new APIResult<List<SU_GoodName>>();
            var list = goodNameRep.GetAll().Result;
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
